package com.its.common.net.core.handler;

import com.its.common.net.core.dto.GenericNetDTO;
import com.its.common.net.core.util.ChannelUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;


/**
 * @Author xiaxp
 * @Date 9/21/22 17:18
 * @Description
 */
public abstract class BaseTcpHandler extends BaseGenericHandler<ByteBuf>  {
    @Override
    protected void extractSendSocketInfo(ChannelHandlerContext ctx, GenericNetDTO<ByteBuf> data) {
        GenericNetDTO.Sender sender = ChannelUtil.extractRemoteInfo(ctx.channel());
        data.setSender(sender);
    }

    @Override
    protected byte[] extract2bytes(ByteBuf obj) {
        return byteBuf2bytes(obj);
    }

    @Override
    public abstract void handleData(ChannelHandlerContext ctx, GenericNetDTO<ByteBuf> data);
}
